<?php
/**
 * Magento
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Academic Free License (AFL 3.0)
 * that is bundled with this package in the file LICENSE_AFL.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/afl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@magentocommerce.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade Magento to newer
 * versions in the future. If you wish to customize Magento for your
 * needs please refer to http://www.magentocommerce.com for more information.
 *
 * @copyright   Copyright (c) 2014 X.commerce, Inc. (http://www.magentocommerce.com)
 * @license     http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
 */
?>
<?php

$numColumns = sizeof($this->getColumns());
?>
<?php if($this->getCollection()): ?>
<div class="dashboard-data-wrapper">
    <table class="dashboard-data" id="<?php echo $this->getId() ?>_table">
        <?php
        /* This part is commented to remove all <col> tags from the code. */
        /* foreach ($this->getColumns() as $_column): ?>
        <col <?php echo $_column->getHtmlProperty() ?> />
        <?php endforeach; */ ?>
        <?php if ($this->getHeadersVisibility() || $this->getFilterVisibility()): ?>
            <thead>
                <?php if ($this->getHeadersVisibility()): ?>
                    <tr class="headings">
                    <?php foreach ($this->getColumns() as $_column): ?>
                        <th <?php echo $_column->getHeaderHtmlProperty() ?>><?php echo $_column->getHeaderHtml() ?></th>
                    <?php endforeach; ?>
                    </tr>
                <?php endif; ?>
            </thead>
        <?php endif; ?>
        <tbody>
        <?php if (($this->getCollection()->getSize()>0) && (!$this->getIsCollapsed())): ?>
        <?php foreach ($this->getCollection() as $_index=>$_item): ?>
            <tr title="<?php echo $this->getRowUrl($_item) ?>">
            <?php $i=0;foreach ($this->getColumns() as $_column): ?>
                <td class="<?php echo $_column->getCssProperty() ?> <?php echo ++$i==$numColumns?'last':'' ?>"><?php echo (($_html = $_column->getRowField($_item)) != '' ? $_html : '&nbsp;') ?></td>
            <?php endforeach; ?>
            </tr>
        <?php endforeach; ?>
        <?php elseif ($this->getEmptyText()): ?>
            <tr>
                <td class="<?php echo $this->getEmptyTextClass() ?>" colspan="100"><?php echo $this->getEmptyText() ?></td>
            </tr>
        <?php endif; ?>
        </tbody>
    </table>
</div>
<?php if($this->canDisplayContainer()): ?>
<script type="text/javascript">
var deps = ['mage/adminhtml/grid'];

<?php if (strpos($this->getRowClickCallback(), 'order.')!==false): ?>
deps.push('Magento_Sales/order/create/form')
<?php endif; ?>

require(deps, function(){
    <?php //TODO: getJsObjectName and getRowClickCallback has unexpected behavior. Should be removed ?>

    <?php echo $this->getJsObjectName() ?> = new varienGrid('<?php echo $this->getId() ?>', '<?php echo $this->getGridUrl() ?>', '<?php echo $this->getVarNamePage() ?>', '<?php echo $this->getVarNameSort() ?>', '<?php echo $this->getVarNameDir() ?>', '<?php echo $this->getVarNameFilter() ?>');
    <?php echo $this->getJsObjectName() ?>.useAjax = '<?php echo $this->getUseAjax() ?>';
    <?php if($this->getRowClickCallback()): ?>
        <?php echo $this->getJsObjectName() ?>.rowClickCallback = <?php echo $this->getRowClickCallback() ?>;
    <?php endif; ?>
    <?php if($this->getCheckboxCheckCallback()): ?>
        <?php echo $this->getJsObjectName() ?>.checkboxCheckCallback = <?php echo $this->getCheckboxCheckCallback() ?>;
    <?php endif; ?>
    <?php if($this->getRowInitCallback()): ?>
        <?php echo $this->getJsObjectName() ?>.initRowCallback = <?php echo $this->getRowInitCallback() ?>;
        <?php echo $this->getJsObjectName() ?>.rows.each(function(row){<?php echo $this->getRowInitCallback() ?>(<?php echo $this->getJsObjectName() ?>, row)});
    <?php endif; ?>
    <?php if($this->getMassactionBlock()->isAvailable()): ?>
    <?php echo $this->getMassactionBlock()->getJavaScript() ?>
    <?php endif ?>

});
</script>
<?php endif; ?>
<?php endif ?>
